/**
 * Created by Chen on 2016/3/22.
 */
define(function(require, exports, module){

    var $ = require('jquery');
    require('bootstrap');
    require('bootstrap.select');
    require('jquery.layer');
    require('jquery.icheck');

    var List = require('../../util/list.js');

    exports.loadList = function(param){
        var list = new List();
        list.options = {
            template : "list-template",
            container : "list-data",
            url : $CONFIG.base_url + "/api/topic/list",
            param : param
        };
        list.load(function(){
            $(".topic-details").on('click',function(){
                exports.loadList1({"id":$(this).attr("value") });
            })
        });
    };
    exports.loadList({'directTeacher.id':$CONFIG.uid,'creatorType':1});

    $(".btn-search-submit").click(function(){
        var $form = $("#search-form");

        var postData = $form.serialize();
        exports.loadList(postData);
    });


    //教师通过出题
    $("#list-data").on("click",".topic-teacher-pass",function(){
        var data = $.parseJSON($(this).attr("data"));
        layer.confirm('要通过该题目？', {
            btn: ['确认','取消'], //按钮
            shade: false //不显示遮罩
        }, function(){
            var posting = $.post($CONFIG.base_url + "/api/topic/teacher/pass", data);
            posting.done(function(data){
                if(data == "true") {
                    layer.msg('成功', {icon:1}
                    );
                    window.location.href = $CONFIG.base_url + "/teacher/topic/check/manage";
                }
                if(data == "had_pass") {
                    layer.msg('老湿，已经是通过审核啦！',{icon:9});
                }
                if(data == "had_educator_pass") {
                    layer.msg('教务已经通过啦！',{icon:9});
                }
                if(data == "had_educator_nopass") {
                    layer.msg('教务没有通过审核！',{icon:9});
                }
            })
        }, function(){
        });
    });

    //教师不通过出题
    $("#list-data").on("click",".topic-teacher-nopass",function(){
        var data = $.parseJSON($(this).attr("data"));
        layer.confirm('不通过该题目？', {
            btn: ['确认','取消'], //按钮
            shade: false //不显示遮罩
        }, function(){
            var posting = $.post($CONFIG.base_url + "/api/topic/teacher/nopass", data);
            posting.done(function(data){
                if(data == "true") {
                    layer.msg('成功', {icon:1});
                    window.location.href = $CONFIG.base_url + "/teacher/topic/check/manage";
                }
                if(data == "had_nopass") {
                    layer.msg('老湿，请不要做无意义的操作哦！',{icon:9});
                }
                if(data == "had_educator_pass") {
                    layer.msg('教务已经通过啦！',{icon:9});
                }
                if(data == "had_educator_nopass") {
                    layer.msg('教务没有通过审核！',{icon:9});
                }
            })
        }, function(){
        });
    });

    //显示详情模板
    exports.loadList1 = function(param){
        var list = new List();
        list.options = {
            template : "list-template1",
            container : "list-data1",
            url : $CONFIG.base_url + "/api/topic/details",
            param : param
        };
        list.load();
    };


});
